import Vue from 'vue'
import VueRouter from 'vue-router'
// import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/home"
  },
  // 首页
  {
    path: '/home',
    name: 'home',
    component: () => import('../views/home/index.vue'),
    meta: {
      showtop: true,
      isShownavbar: true
    },
  }, {
    path: '/shoukan',
    name: 'shoukan',
    component: () => import('../views/home/shoukan.vue'),
    meta: {
      shoukan: true
    },
  }, {
    path: '/Detailtopic',
    name: 'Detailtopic',
    component: () => import('../views/home/Detailtopic.vue'),
    meta: {
      kanlie: true
    },
  }, {
    path: '/shoudetails',
    name: 'shoudetails',
    component: () => import('../views/home/shoudetails.vue'),
    meta: {
      xiangqing: true
    },
  }, {
    path: '/shopcar',
    name: 'shopcar',
    component: () => import('../views/home/shopcar.vue'),
    meta: {
      shopcar: true
    },
  },
  // 分类
  {
    path: '/ification',
    name: 'ification',
    component: () => import('../views/ification/index.vue'),
    meta: {
      isShownavbar: true,
      fenlei: true
    }
  },
  {
    path: '/branchProduct',
    name: 'branchProduct',
    component: () => import('../views/ification/branchProduct.vue'),
    meta: {
      fenleishang: true
    }
  },
  // 购物车
  {
    path: '/Shopping',
    name: 'Shopping',
    component: () => import('../views/Shopping/index.vue')
    , meta: {
      isShownavbar: true
    }
  },
  // 个人
  {
    path: '/personal',
    name: 'personal',
    component: () => import('../views/personal/index.vue')
    , meta: {
      isShownavbar: true
    }
  }, {
    path: '/addres',
    name: 'addres',
    component: () => import('../views/personal/addres.vue')
    , meta: {

    }
  }, {
    path: '/Myorder',
    name: 'Myorder',
    component: () => import('../views/personal/Myorder.vue')
    , meta: {
      Myorder: true
    }
  },{
    path: '/orderdetails',
    name: 'orderdetails',
    component: () => import('../views/personal/orderdetails.vue')
    , meta: {
      orderdetails: true
    }
  },


  //登录
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
    , meta: {

    }
  },
  // 注册
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/register.vue')
    , meta: {

    }
  },


]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});
// 返回上一级
router.goBack = () => {
  router.back();
}

// router.beforeEach((to, from, next) => {
//   if (localStorage.getItem("token")) {
//     next();
//   } else {
//     if (to.path == "/login") {
//       next();
//     } else {
//       next("/login");
//     }
//   }
// });

//全局的路由守卫 守卫所有的跳转，如果已经登陆了就正常执行跳转
// 如果没有登陆就跳转到登陆页面 会有一个死循环 所以要判断是否是登陆页面 如果是登陆页面就继续

export default router
